<template>
  <div class="new-category">
    <div class="content" v-for="item in newCategoryList" :key="item.id">
      <div class="title">{{ item.name | nameFilters }}</div>
      <div class="main">
        <div @click="mainItemClick(index, items)" class="main-item" v-for="(items, index) in item.goodsList" :key="items.id">
          <img :src="items.list_pic_url" alt="" />
          <div class="texts">
            <p class="titles">
              <span>{{ items.name }} </span>
            </p>
            <p class="price">
              {{ items.retail_price | filterPrice }}
            </p>
          </div>
        </div>
        <div class="main-item main-items" @click="itemsClick(item)">
          <div class="title">{{ item.name | nameFilters }}</div>
          <div class="circle">
            <van-icon name="down" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    newCategoryList: {
      type: Array,
      default() {
        return [];
      },
    }
  },
  methods: {
    mainItemClick(index, items) {
      console.log(index, items)
      let id = items.id
      console.log(id)
      this.$router.push({
        path: '/detail',
        query: {
          id,
        }
      })
    },
    // 跳到分类list 页面去
    itemsClick(item) {
      let index = this.newCategoryList.findIndex(items => items.id == item.id)
      // console.log(index)
      let id = this.newCategoryList[index].id;
      console.log(id)
      this.$router.push({
        path: '/categorylist',
        query: {
          id
        }
      })
    }
  },
  filters: {
    nameFilters(val) {
      return val + "好物";
    },
    filterPrice(val) {
      return "¥" + val;
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  display: flex;
  flex-direction: column;

  .title {
    padding: 20px;
    text-align: center;
  }
  .main {
    // width: 100%;
    display: flex;
    // justify-content: space-between;
    flex-wrap: wrap;
    margin: 0px 10px;
    .main-item {
      flex: 48%;
      display: flex;
      background-color: #fff;
      flex-direction: column;
      margin-bottom: 10px;
      margin-right: 5px;
      img {
        width: 100%;
      }
      .price {
        color: #f00;
        margin: 10px 0;
      }
      p {
        // span {
        //   white-space: nowrap;
        //   overflow: hidden;
        //   text-overflow: ellipsis;
        // }
      }
    }
    .main-items {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      font-size: 18px;
      color: #898989;
      // .title {

      // }
      .van-icon {
        transform: rotate(-90deg);
        border-radius: 50%;
        padding: 5px;

        // font-size: 18px;
        border: 1px solid #898989;
      }
    }
  }
}
</style>